#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

class Solution{
    public:
    Solution(){
        Mymap[1] = 'I';
        Mymap[5] = 'V';
        Mymap[10] = 'X';
        Mymap[50] = 'L';
        Mymap[100] = 'C';
        Mymap[500] = 'D';
        Mymap[1000] = 'M';
    }
    
    //my ans
    string ans1(int num){
        vector<int> counts;
        int temp, div = 1000;
        for(int i = 0; i != 4; i++){
            temp = num / div;
            num = num % div;
            div = div / 10;
            counts.push_back(temp);
        }
        int length = counts.size();
        string s = "";
        for(int i = 0; i != length; i++){
            switch(counts[i]){
                case 1:
                    if(i == 0){
                        s = s + "M";
                    }else if(i == 1){
                        s = s + "C";
                    }else if(i == 2){
                        s = s + "X";
                    }else{
                        s = s + "I";
                    }
                    break;
                case 2:
                    if(i == 0){
                        s = s + "MM";
                    }else if(i == 1){
                        s = s + "CC";
                    }else if(i == 2){
                        s = s + "XX";
                    }else{
                        s = s + "II";
                    }
                    break;
                case 3:
                    if(i == 0){
                        s = s + "MMM";
                    }else if(i == 1){
                        s = s + "CCC";
                    }else if(i == 2){
                        s = s + "XXX";
                    }else{
                        s = s + "III";
                    }
                    break;
                case 4:
                    if(i == 0){
                        break;
                    }else if(i == 1){
                        s = s + "CD";
                    }else if(i == 2){
                        s = s + "XL";
                    }else{
                        s = s + "IV";
                    }
                    break;
                case 5:
                    if(i == 0){
                        break;
                    }else if(i == 1){
                        s = s + "D";
                    }else if(i == 2){
                        s = s + "L";
                    }else{
                        s = s + "V";
                    }
                    break;
                case 6:
                    if(i == 0){
                        break;
                    }else if(i == 1){
                        s = s + "DC";
                    }else if(i == 2){
                        s = s + "LX";
                    }else{
                        s = s + "VI";
                    }
                    break;
                case 7:
                    if(i == 0){
                        break;
                    }else if(i == 1){
                        s = s + "DCC";
                    }else if(i == 2){
                        s = s + "LXX";
                    }else{
                        s = s + "VII";
                    }
                    break;
                case 8:
                    if(i == 0){
                        break;
                    }else if(i == 1){
                        s = s + "DCCC";
                    }else if(i == 2){
                        s = s + "LXXX";
                    }else{
                        s = s + "VIII";
                    }
                    break;
                case 9:
                    if(i == 0){
                        break;
                    }else if(i == 1){
                        s = s + "CM";
                    }else if(i == 2){
                        s = s + "XC";
                    }else{
                        s = s + "IX";
                    }
                    break;
                default:
                    break;
            }
        }

        return s;
    }

    void show(vector<int>& num){
        int length = num.size();
        for(int i = 0; i != length; i++){
            cout << num[i] << " " << ends;
        }
        cout << endl;
    }

    private:
    map<int, char> Mymap;
};

void test1(){
    Solution s;
    int num = 3749;
    string ret = s.ans1(num);
    cout << ret << endl;
}

void test2(){
    Solution s;
    int num = 58;
    string ret = s.ans1(num);
    cout << ret << endl;
}

void test3(){
    Solution s;
    int num = 1994;
    string ret = s.ans1(num);
    cout << ret << endl;
}

void test4(){
    Solution s;
    int num = 5;
    string ret = s.ans1(num);
    cout << ret << endl;
}

int main(void){
    test1();
    test2();
    test3();
    test4();

    return 0;
}